package com.lai.shop.headler;

import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;
import java.time.LocalDateTime;

@Component
@Slf4j
public class MyMetaObjectHandler implements MetaObjectHandler {

    @Override
    public void insertFill(MetaObject metaObject) {
        log.info("插入createTime");
        //this.strictInsertFill(metaObject, "createTime", LocalDateTime.class, LocalDateTime.now()); // 起始版本 3.3.0(推荐使用)
        this.strictUpdateFill(metaObject, "createTime", DateTime.class, DateUtil.date()); // 起始版本 3.3.3(推荐)
        this.strictUpdateFill(metaObject, "updateTime", DateTime.class, DateUtil.date());
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        log.info("插入updateTime");
        this.strictUpdateFill(metaObject, "updateTime", DateTime.class, DateUtil.date()); // 起始版本 3.3.0(推荐) }
    }
}
